using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace TowerDefence_Zombie
{
    [RequireComponent(typeof(Button))]
    [DisallowMultipleComponent]
    public class ButtonTweenAnim : MonoBehaviour
    {
        #region btnTween

        [SerializeField] private Ease btnEase = Ease.Linear;

        [SerializeField] private Vector3 btnToScale = new(1.2f, 1.2f, 1.2f);

        [SerializeField] private float btnTimer = 0.2f;

        #endregion

        [SerializeField] private Button tweenBtn;

        private Vector3 orignalScale;

        private void Awake()
        {
            orignalScale = transform.localScale;
            tweenBtn.onClick.AddListener(OnBtnClick);
        }

        private void OnBtnClick()
        {
            if (gameObject != null)
            {
                transform.DOKill();
                transform.DOScale(btnToScale, btnTimer)
                    .SetEase(btnEase)
                    .From(orignalScale);
            }
        }

#if UNITY_EDITOR
        private void OnValidate()
        {
            if (tweenBtn == null)
            {
                tweenBtn = GetComponent<Button>();
            }
        }
#endif
    }
}
